package com.suneee.trades.dao.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.suneee.orm.GenericDao;
import com.suneee.orm.util.WhereClauseBuilder;
import com.suneee.trades.bean.TradesInfoDTO;
import com.suneee.trades.dao.ViewShoppDetailExportDao;
import com.suneee.trades.entity.ViewShoppDetailExport;

@Repository("viewShoppDetailExportDao")
public class ViewShoppDetailExportDaoImpl extends GenericDao<ViewShoppDetailExport, String>
		implements ViewShoppDetailExportDao {

	@Override
	public List<ViewShoppDetailExport> exportXls(TradesInfoDTO dto) {
		WhereClauseBuilder wcb = new WhereClauseBuilder(" select * from v_shopp_detail_export where 1=1 ");
		wcb.equals("title", dto.getTitle());
		wcb.equals("shop_id", dto.getShopId());
		wcb.equals("company_name", dto.getCompanyName());
		wcb.equals("buyer_nick", dto.getBuyerNick());
		wcb.contains("tid", dto.getTid());
		wcb.between("created", dto.getCreateStartTime(), dto.getCreateEndTime());
		wcb.between("audit_time", dto.getReviewStartTime(), dto.getReviewEndTime());
		wcb.equals("enterprise_code",dto.getEnterpriseCode());
		Integer[] shoppId = dto.getShoppId();
		if (null != shoppId && shoppId.length > 0) {
			List<Object> list = new ArrayList<>();
			Collections.addAll(list, shoppId);
			wcb.in("shopp_id", list);
		}
		return this.executeQuery(wcb.getSql(), wcb.getArgs());
	}

}
